<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;
class Config extends Common
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        if (request()->isPost()) {
            $data=input('post.');
            if ($_FILES['logo']['tmp_name']) {
                $file = request()->file('logo');
                if ($file) {
                    $data['logo']=$this->uploadimg($file);
                }
            }
            if ($_FILES['ewm']['tmp_name']) {
                $file = request()->file('ewm');
                if ($file) {
                    $data['ewm']=$this->uploadimg($file);
                }
            }
            if ($_FILES['water_img']['tmp_name']) {
                $file = request()->file('water_img');
                if ($file) {
                    $data['water_img']=$this->uploadimg($file);
                }
            }
            $res=db('config')->find();
            if (!$res) {
              db('config')->insert(['config'=>json_encode($data,JSON_UNESCAPED_UNICODE)]);
            }else {
             $result=db('config')->where('id',$res['id'])->update(['config'=>json_encode($data,JSON_UNESCAPED_UNICODE)]);
             if (!$result) {
                 $this->error('配置信息修改失败','config/index');
             }
             $this->success('配置设置成功');
          }
        }
        $config=db('config')->find();
       
        $this->assign('config',json_decode($config['config'],true));
        return view();
    }

  

    
}
